package com.teamtgv.shareshark.result;

import java.util.Comparator;

public class ResultComparator {

	private static Comparator<Result> dateComparator;
	private static Comparator<Result> distanceComparator;
	private static Comparator<Result> ratingComparator;

	public static Comparator<Result> getDateComparator() {
		if (dateComparator == null) {
			dateComparator = new Comparator<Result>() {

				@Override
				public int compare(Result lhs, Result rhs) {
					return rhs.getDateRecommended().compareTo(
							lhs.getDateRecommended());
				}
			};
		}
		return dateComparator;
	}

	public static Comparator<Result> getDistanceComparator() {
		if (distanceComparator == null) {
			distanceComparator = new Comparator<Result>() {
				@Override
				public int compare(Result lhs, Result rhs) {
					return lhs.getLocation().compareTo(rhs.getLocation());
				}
			};
		}
		return distanceComparator;
	}

	public static Comparator<Result> getRatingComparator() {
		if (ratingComparator == null) {
			ratingComparator = new Comparator<Result>() {
				@Override
				public int compare(Result lhs, Result rhs) {
					int ratingLeft = lhs.getPlusRating() - lhs.getMinRating();
					int ratingRight = rhs.getPlusRating() - rhs.getMinRating();
					if (ratingLeft > ratingRight)
						return -1;
					else if (ratingLeft == ratingRight)
						return 0;
					else
						return 1;
				}
			};
		}
		return ratingComparator;
	}
}
